<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let fn1 = async () => {
            console.log(123);
        }
        // 获取函数的返回值 没写return就会得到undefined
        console.log(fn1().then(res => {
            console.log(res);
        }));

        async function fn2() {
            let str = '白居易，字乐天，号香山居士'
            return str
        }
        console.log(fn2().then(res => {
            console.log(res);
        }));

        let fnLibai = () => {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    console.log(11);
                    resolve('李白，国服第一')
                }, 1000)
            })
        }

        let fn3 = async () => {
            let str = '';
            console.log(22);
            // 转换为同步代码，逐行执行  之前会跳过异步代码先执行同步，现在是等待异步执行
            let data = await fnLibai();
            console.log(33);
            return data
        }
        console.log(fn3());
    </script>
</body>

</html>